setwd("/home/jc227089/SRE/KB/DispOnly/limits/PBS/")

H<-seq(0, 1, 0.1)
b<-seq(0.05, 1, 0.05)

script.file<-"/home/jc227089/evo-dispersal/KBGrad/DispOnly/limits/h_by_b/h_by_b.R"
fname<-"Hbyb_limits"

for (ii in 1:length(H)) {
	for (jj in 1:length(b)){
		fid<-jj+(ii-1)*length(b)
		##create the sh file
		zz = file(paste(fname, fid,'.sh',sep=''),'w')
		cat('##################################\n',file=zz)
		cat('#!/bin/sh\n',file=zz)
		cat('cd $PBS_O_WORKDIR\n',file=zz)
		cat("R CMD BATCH --no-save --no-restore '--args fID=",fid, " h2D=", H[ii], " b=", b[jj], "' ", sep="", file=zz)
		cat(script.file, " ", paste(fname, fid,'.Rout',sep=''), "\n", sep="",file=zz)
		cat('##################################\n',file=zz)
		close(zz)
				
		#submit the job
		#system(paste("qsub -m n ", paste(fname, fid,".sh",sep=""),sep=""))
	}
}


setwd("/home/jc227089/SRE/KB/DispOnly/limits/PBS/")
script.file<-"/home/jc227089/evo-dispersal/KBGrad/DispOnly/limits/h_by_b/One_pop_dynamic.R"
fname<-"Onepop"


		fid<-1
		##create the sh file
		zz = file(paste(fname, fid,'.sh',sep=''),'w')
		cat('##################################\n',file=zz)
		cat('#!/bin/sh\n',file=zz)
		cat('cd $PBS_O_WORKDIR\n',file=zz)
		cat("R CMD BATCH --no-save --no-restore ", sep="", file=zz)
		cat(script.file, " ", paste(fname, fid,'.Rout',sep=''), "\n", sep="",file=zz)
		cat('##################################\n',file=zz)
		close(zz)
				
		#submit the job
		system(paste("qsub -m n ", paste(fname, fid,".sh",sep=""),sep=""))